<?php

/**
 * projectOptions actions.
 *
 * @package    LIAnnot
 * @subpackage projectOptions
 * @author     Cedric Richier
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class projectOptionsActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
    $this->skinOption = Doctrine::getTable("skin")->findOneByUserName($this->getUser()->getUserName());
  	
  	if(empty($this->skinOption)) 
  		$this->skinOption = new Skin();
  }
  
  public function executeUpdateFeatsOptions(sfWebRequest $request) {
  	
  	$frame_r = $request->getparameter("frame_r");
  	$frame_g = $request->getparameter("frame_g");
  	$frame_b = $request->getparameter("frame_b");
  	
  	$att_r = $request->getparameter("att_r");
  	$att_g = $request->getparameter("att_g");
  	$att_b = $request->getparameter("att_b");
  	
  	$tok_r = $request->getparameter("tok_r");
  	$tok_g = $request->getparameter("tok_g");
  	$tok_b = $request->getparameter("tok_b");
  	
  	$turn_r = $request->getparameter("turn_r");
  	$turn_g = $request->getparameter("turn_g");
  	$turn_b = $request->getparameter("turn_b");
  	
  	$whiteboard_r = $request->getparameter("whiteboard_r");
  	$whiteboard_g = $request->getparameter("whiteboard_g");
  	$whiteboard_b = $request->getparameter("whiteboard_b");
  	
  	$skinOption = Doctrine::getTable("skin")->findOneByUserName($this->getUser()->getUserName());
  	
  	if(empty($skinOption)) {
  		$skinOption = new Skin();
  		$skinOption->setUserName($this->getUser()->getUserName());
  	}
  	
  	$skinOption->setFrameR($frame_r);
  	$skinOption->setFrameG($frame_g);
  	$skinOption->setFrameB($frame_b);
  	
  	$skinOption->setAttR($att_r);
  	$skinOption->setAttG($att_g);
  	$skinOption->setAttB($att_b);
  	
  	$skinOption->setTokR($tok_r);
  	$skinOption->setTokG($tok_g);
  	$skinOption->setTokB($tok_b);
  	
  	$skinOption->setTurnR($turn_r);
  	$skinOption->setTurnG($turn_g);
  	$skinOption->setTurnB($turn_b);
  	
  	$skinOption->setWhiteboardR($whiteboard_r);
  	$skinOption->setWhiteboardG($whiteboard_g);
  	$skinOption->setWhiteboardB($whiteboard_b);
  	
  	$skinOption->save();
  	
  	echo "ok";
  	return sfView::NONE;
  }
  
  public function executeGetFeatOptions(sfWebRequest $request) {
 	$skinOption = Doctrine::getTable("skin")->findOneByUserName($this->getUser()->getUserName());
  	
  	if(empty($skinOption)) {
  		$skinOption = new Skin();
  	}
  	
  	$tab = array();
  	$tab["frame_r"] = $skinOption->getFrameR();
  	$tab["frame_g"] = $skinOption->getFrameG();
  	$tab["frame_b"] = $skinOption->getFrameB();
  	
  	$tab["att_r"] = $skinOption->getAttR();
  	$tab["att_g"] = $skinOption->getAttG();
  	$tab["att_b"] = $skinOption->getAttB();
  	
  	$tab["tok_r"] = $skinOption->getTokR();
  	$tab["tok_g"] = $skinOption->getTokG();
  	$tab["tok_b"] = $skinOption->getTokB();
  	
  	$tab["turn_r"] = $skinOption->getTurnR();
  	$tab["turn_g"] = $skinOption->getTurnG();
  	$tab["turn_b"] = $skinOption->getTurnB();
  	
  	$tab["whiteboard_r"] = $skinOption->getWhiteboardR();
  	$tab["whiteboard_g"] = $skinOption->getWhiteboardG();
  	$tab["whiteboard_b"] = $skinOption->getWhiteboardB();
  	
  	$json = json_encode($tab , JSON_FORCE_OBJECT);
  	
  	echo $json;
  	
  	return sfView::NONE;
  }
  
  public function executeUploadBackgroundWorkSpace(sfWebRequest $request) {
  	
  	// valeur de retour: 1  = success , 0 = failure , 2 = fichier trop volumineux ,  3 = extension invalide , 4 = pas de fichier 
  	$this->result = 0;
  	
  	if(!empty($_FILES['file'])) {
		$fileToUpload = new Fichier("file");
		//  si le fichier n'est pas trop volumineux
		if (!$fileToUpload->fichierVolumineux()) {
			if (OutilsImage::extensionValide($fileToUpload->getName())) {
				
				$extension = OutilsImage::extensionFichier($fileToUpload->getName());
				
				$transfertSuccess = $fileToUpload->tranfererFichier(
					sfConfig::get('sf_upload_dir').'/backgrounds/bg_'.$this->getUser()->getUserName().".$extension");
					
				if($transfertSuccess)
					$this->result = 1;
						
			} else {
				$this->result = 3;
			}
				
		} else {
			$this->result = 2;
		}
	} else {
		$this->result = 4;
	}
  }
}
























